package com.whq.thrift.api.thrift.as.service.test;

import java.util.HashMap;
import java.util.Map;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransportException;

import com.whq.thrift.api.common.thriftserver.ApiRequest;

public class ApiRequestClientSyncDemo {
	public static void main(String[] args) {
		long startMs = System.currentTimeMillis();
		try { 
			TFramedTransport transport = new TFramedTransport(new TSocket("localhost", 6001, 10000)); 
			transport.open();
			TProtocol protocol = new TBinaryProtocol(transport); 
            ApiRequest.Client syncClient = new ApiRequest.Client(protocol); 
            System.out.println("Client calls ....."); 
            
            Map<String, String> params = new HashMap<String, String>(0);
            params.put("method", "account.query");
            params.put("name", "abcd");
            
            Map<String, String> ctx = new HashMap<String, String>(0);
            ctx.put("flowId", "abcd");
            
            String response = syncClient.handleRequest(params, ctx);
            System.out.println("response: " + response);
            
            transport.close(); 
        } catch (TTransportException e) { 
            e.printStackTrace(); 
        } catch (TException e) { 
        	e.printStackTrace(); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        }
		
		long consumeMs = System.currentTimeMillis() - startMs;
		System.out.println("consume: " + consumeMs + " ms");
	}
	
	
	
	
}
